<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_SESSION['juese_id']!=1){
	exi('您无权访问！','error');
}
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	$return['params']['status']=intval($_RQ['status']);
	if($_RQ['memberid']){
		$params['memberid']=intval($_RQ['memberid']);
		$return['params']['memberid']=intval($_RQ['memberid']);
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_yxw_yonghu_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=$this->model('yonghu')->member_show($item['yonghuid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'售后信息','type'=>'member'),
			array('type'=>'radio2','title'=>'申请事项','name'=>'setstatus','options'=>'setstatus'),
			array('name'=>'remark','title'=>'原因备注','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio2','options'=>'status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','action'=>'/store.yonghu_log/check/','title'=>'审批','show'=>array('status'=>array(0,3))),
			array('type'=>'modal','action'=>'/store.yonghu_log/remark14/','title'=>'财务审批不通过原因','show'=>array('status'=>3)),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>25,'action'=>'jy_yxw/member.get_member/','name'=>'mid','title'=>'选择客户'),
		),
	);
	$return['status']=array('待审核','审核通过','审核不通过','财务审核不通过');
	$return['setstatus']=$this->setstatus;
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='remark14'){
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_yonghu_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择客户','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'look',
	);
	$htmls['look']=array(
		array('type'=>'text','title'=>'财务审批不通过原因','name'=>'remark14'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		if($post['check'] && !$post['remark1']){
			exi('请填写审核不通过的原因！','error');
		}
		$id=$post['id'];
		$update=array(
			'remark1'=>trim($post['remark1']),
			'status'=>$post['check']?2:1,
		);
		//print_r($post);exit;
		pdo_update('jy_yxw_yonghu_log',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		if(!$post['check']){
			$update=array('setstatusid'=>$id);
			if($post['setstatus']==1){
				$update['storeid']=$post['tostoreid'];
				$update['classid']=$post['toclassid'];
			}elseif($post['setstatus']==2){
				$update['classid']=$post['toclassid'];
			}elseif($post['setstatus']==3){
				$update['status']=19;
				$memberstatus=19;
			}elseif($post['setstatus']==4){
				$update['status']=19;
				$memberstatus=19;
			}elseif($post['setstatus']==5){
				$update['status']=28;
				$memberstatus=17;
			}elseif($post['setstatus']==6){
				$update['status']=12;
				$memberstatus=12;
			}elseif($post['setstatus']==7){
				$update['status']=17;
				$memberstatus=17;
			}elseif($post['setstatus']==8){
				$update['status']=12;
				$memberstatus=12;
			}elseif($post['setstatus']==9){
				$update['status']=12;
				$memberstatus=12;
			}elseif($post['setstatus']==10){
				$update['status']=27;
				$memberstatus=13;
			}
			pdo_update('jy_yxw_yonghu',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['yonghuid']));
			if($memberstatus){
				$memberid=pdo_getcolumn('jy_yxw_yonghu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['yonghuid']),'memberid');
				pdo_update('jy_yxw_member',array('status'=>$memberstatus),array('uniacid'=>$_SESSION['uniacid'],'id'=>$memberid));
				$member=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$memberid));
				if($post['setstatus']==3){
					$data=array(
						'tuiyonghuid'=>$post['id'],
						'memberid'=>$memberid,
						'fee'=>$post['danfee'],
						'isfee'=>$post['danfee']-$post['danfee']['lastfee'],
						'remark'=>trim($post['remark']),
						'worker5id'=>$member['worker5id'],
						'worker6id'=>$member['worker6id'],
						'workerheid'=>$member['workerheid'],
						'type'=>1,
						'status'=>1,
					);
					$data['uniacid']=$_SESSION['uniacid'];
					$data['storeid']=$member['storeid'];
					$data['createtime']=time();
					$this->insert('tuifee_log',$data);
				}
			}
		}
		exi('操作成功！','','jy_yxw/store.yonghu_log/');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_yonghu_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择客户','error');
	}
	$item['images']=json_decode($item['images'],true);
	$item['setstatustitile']=$this->setstatus[$item['setstatus']];
	$item['title']=pdo_getcolumn('jy_yxw_yonghu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['yonghuid']),'title');
	$item['mobile']=pdo_getcolumn('jy_yxw_yonghu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['yonghuid']),'mobile');
	$item['storetitle']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']),'title');
	$item['classtitle']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'title');
	$item['fuwuid']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'fuwuid');
	$item['fuwu']=pdo_getcolumn('jy_yxw_fuwu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['fuwuid']),'title');
	$item['fuwuprice']=pdo_getcolumn('jy_yxw_fuwu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['fuwuid']),'price');
	$item['workername']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['workerid']),'title');
	$item['tostoretitle']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['tostoreid']),'title');
	$item['toclasstitle']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['toclassid']),'title');
	$item['setinfo']=json_decode($item['setinfo'],true);
	$item['check']=0;
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'审核退成交',
	);
	$htmls['edit']=array(
		array('type'=>'string','title'=>'管理事项','name'=>'setstatustitile','read'=>true),
		array('type'=>'title','title'=>'售后当前信息'),
		array('type'=>'string_two2','title1'=>'售后姓名','title2'=>'电话','name1'=>'title','name2'=>'mobile','read'=>true),
		array('type'=>'string_two2','title1'=>'门店','title2'=>'使用','name1'=>'storetitle','name2'=>'fuwu','read'=>true),
		array('type'=>'string_two2','title1'=>'售后群','title2'=>'成交日期','name1'=>'classtitle','name2'=>'buygoodsday','read'=>true),
		array('type'=>'string_two2','title1'=>'使用原价','title2'=>'实际缴费','name1'=>'fuwuprice','name2'=>'danfee','read'=>true),
		array('type'=>'string_two2','title1'=>'总课次','title2'=>'已上课次','name1'=>'keshi','name2'=>'iskeshi','read'=>true),
		array('type'=>'title','title'=>'转门店信息','show'=>array('setstatus'=>1)),
		array('type'=>'title','title'=>'转班信息','show'=>array('setstatus'=>2)),
		array('type'=>'title','title'=>'退学信息','show'=>array('setstatus'=>3)),
		array('type'=>'title','title'=>'退学不退费信息','show'=>array('setstatus'=>4)),
		array('type'=>'title','title'=>'停课信息','show'=>array('setstatus'=>5)),
		array('type'=>'title','title'=>'复课信息','show'=>array('setstatus'=>6)),
		array('type'=>'title','title'=>'休学信息','show'=>array('setstatus'=>7)),
		array('type'=>'title','title'=>'复学信息','show'=>array('setstatus'=>8)),
		array('type'=>'title','title'=>'重修信息','show'=>array('setstatus'=>9)),
		array('type'=>'title','title'=>'结课信息','show'=>array('setstatus'=>10)),
		array('type'=>'tip','title'=>'提交后，将进入审批阶段；需要店长或主管审批之后，才能生效'),
		array('type'=>'string','title'=>'转售后群','name'=>'tostoretitle','show'=>array('setstatus'=>1),'read'=>true),
		array('type'=>'string','title'=>'转售后群','name'=>'toclasstitle','show'=>array('setstatus'=>1),'read'=>true),
		array('type'=>'string_two2','title1'=>'剩余课时','title2'=>'课时单价','name1'=>'lastkeshi','name2'=>'onefee','read'=>true),
		array('type'=>'string_two2','title1'=>'剩余费用','title2'=>'需补费用','name1'=>'lastfee','read1'=>true,'name2'=>'bufee','show'=>array('setstatus'=>1),'read'=>true),
		array('type'=>'string','title'=>'转售后群','name'=>'toclasstitle','show'=>array('setstatus'=>2),'read'=>true),
		array('type'=>'string_two2','title1'=>'剩余费用','title2'=>'实际退费','name1'=>'lastfee','read1'=>true,'name2'=>'tuifee','show'=>array('setstatus'=>3),'read'=>true),
		array('type'=>'text','name'=>'remark','title'=>'备注','read'=>true),
		array('type'=>'images','name'=>'images','title'=>'凭证','read'=>true),
		array('type'=>'string_two2','title1'=>'操作人','title2'=>'操作时间','name1'=>'workername','name2'=>'setday','read'=>true),
		array('type'=>'radio','title'=>'审批','name'=>'check','options'=>'check'),
		array('type'=>'text','title'=>'审核不通过原因','name'=>'remark1','show'=>array('check'=>1)),
	);
	$return['check']=array('审核通过','审核不通过');
	$return['htmls']=$htmls;
	exi($return);
}